home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / toolbar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-26  |  42.6 KB  |  1,500 lines

  1. /* Generic toolbar implementation.
  2.    Copyright (C) 1995 Board of Trustees, University of Illinois.
  3.    Copyright (C) 1995 Sun Microsystems.
  4.  
  5. This file is part of XEmacs.
  6.  
  7. XEmacs is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with XEmacs; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* Synched up with: Not in FSF. */
  22.  
  23. #include <config.h>
  24. #include "lisp.h"
  25.  
  26. #include "buffer.h"
  27. #include "frame.h"
  28. #include "device.h"
  29. #include "glyphs.h"
  30. #include "redisplay.h"
  31. #include "toolbar.h"
  32. #include "window.h"
  33.  
  34. Lisp_Object Vtop_toolbar, Vbottom_toolbar;
  35. Lisp_Object Vleft_toolbar, Vright_toolbar;
  36.  
  37. Lisp_Object Vtop_toolbar_height, Vbottom_toolbar_height;
  38. Lisp_Object Vleft_toolbar_width, Vright_toolbar_width;
  39.  
  40. Lisp_Object Vdefault_toolbar, Vdefault_toolbar_position;
  41. Lisp_Object Vtoolbar_buttons_captioned_p;
  42.  
  43. /* Qdefault defined in general.c */
  44. Lisp_Object Qtop, Qbottom, Qleft, Qright;
  45.  
  46. Lisp_Object Qtoolbar;
  47.  
  48. Lisp_Object Qtoolbar_buttonp;
  49. Lisp_Object Q2D, Q3D, Q2d, Q3d;
  50. Lisp_Object Q_size;
  51. extern Lisp_Object Q_style;    /* defined in menubar.c */
  52.  
  53. Lisp_Object Qinit_toolbar_from_resources;
  54.  
  55.  
  56. static Lisp_Object
  57. mark_toolbar_data (Lisp_Object obj, void (*markobj) (Lisp_Object))
  58. {
  59.   struct toolbar_data *data = (struct toolbar_data *) XPNTR (obj);
  60.   ((markobj) (data->last_toolbar_buffer));
  61.   return (data->toolbar_buttons);
  62. }
  63.  
  64. DEFINE_LRECORD_IMPLEMENTATION ("toolbar-data", toolbar_data,
  65.                    mark_toolbar_data, 0, 0, 0, 0,
  66.                    struct toolbar_data);
  67.  
  68. static Lisp_Object
  69. mark_toolbar_button (Lisp_Object obj, void (*markobj) (Lisp_Object))
  70. {
  71.   struct toolbar_button *data = (struct toolbar_button *) XPNTR (obj);
  72.   ((markobj) (data->next));
  73.   ((markobj) (data->frame));
  74.   ((markobj) (data->up_glyph));
  75.   ((markobj) (data->down_glyph));
  76.   ((markobj) (data->disabled_glyph));
  77.   ((markobj) (data->cap_up_glyph));
  78.   ((markobj) (data->cap_down_glyph));
  79.   ((markobj) (data->cap_disabled_glyph));
  80.   ((markobj) (data->callback));
  81.   ((markobj) (data->enabled_p));
  82.   return (data->help_string);
  83. }
  84.  
  85. static void
  86. print_toolbar_button (Lisp_Object obj, Lisp_Object printcharfun,
  87.               int escapeflag)
  88. {
  89.   struct toolbar_button *tb = XTOOLBAR_BUTTON (obj);
  90.   char buf[100];
  91.  
  92.   if (print_readably)
  93.     error ("printing unreadable object #<toolbar-button 0x%x>",
  94.        tb->header.uid);
  95.  
  96.   sprintf (buf, "#<toolbar-button 0x%x>", tb->header.uid);
  97.   write_c_string (buf, printcharfun);
  98. }
  99.  
  100. DEFINE_LRECORD_IMPLEMENTATION ("toolbar-button", toolbar_button,
  101.                    mark_toolbar_button, print_toolbar_button,
  102.                    0, 0, 0,
  103.                    struct toolbar_button);
  104.  
  105. DEFUN ("toolbar-button-p", Ftoolbar_button_p, Stoolbar_button_p, 1, 1, 0,
  106.        "Return non-nil if OBJECT is a toolbar button.")
  107.      (object)
  108.      Lisp_Object object;
  109. {
  110.   return (TOOLBAR_BUTTONP (object) ? Qt : Qnil);
  111. }
  112.  
  113. /* Only query functions are provided for toolbar buttons.  They are
  114.    generated and updated from a toolbar description list.  Any
  115.    directly made changes would be wiped out the first time the toolbar
  116.    was marked as dirty and was regenerated.  The exception to this is
  117.    set-toolbar-button-down-flag.  Having this allows us to control the
  118.    toolbar from elisp.  Since we only trigger the button callbacks on
  119.    up-mouse events and we reset the flag first, there shouldn't be any
  120.    way for this to get us in trouble (like if someone decides to
  121.    change the toolbar from a toolbar callback). */
  122.  
  123. DEFUN ("toolbar-button-callback", Ftoolbar_button_callback,
  124.        Stoolbar_button_callback, 1, 1, 0,
  125.        "Return the callback function associated with the toolbar BUTTON.")
  126.      (button)
  127.      Lisp_Object button;
  128. {
  129.   CHECK_TOOLBAR_BUTTON (button, 0);
  130.  
  131.   return (XTOOLBAR_BUTTON (button)->callback);
  132. }
  133.  
  134. DEFUN ("toolbar-button-help-string", Ftoolbar_button_help_string,
  135.        Stoolbar_button_help_string, 1, 1, 0,
  136.        "Return the help string function associated with the toolbar BUTTON.")
  137.      (button)
  138.      Lisp_Object button;
  139. {
  140.   CHECK_TOOLBAR_BUTTON (button, 0);
  141.  
  142.   return (XTOOLBAR_BUTTON (button)->help_string);
  143. }
  144.  
  145. DEFUN ("toolbar-button-enabled-p", Ftoolbar_button_enabled_p,
  146.        Stoolbar_button_enabled_p, 1, 1, 0,
  147.        "Return t if BUTTON is active.")
  148.      (button)
  149.      Lisp_Object button;
  150. {
  151.   CHECK_TOOLBAR_BUTTON (button, 0);
  152.  
  153.   return (XTOOLBAR_BUTTON (button)->enabled ? Qt : Qnil);
  154. }
  155.  
  156. DEFUN ("set-toolbar-button-down-flag", Fset_toolbar_button_down_flag,
  157.        Sset_toolbar_button_down_flag, 2, 2, 0,
  158.        "Don't touch.")
  159.      (button, flag)
  160.      Lisp_Object button, flag;
  161. {
  162.   struct toolbar_button *tb;
  163.   char old_flag;
  164.  
  165.   CHECK_TOOLBAR_BUTTON (button, 0);
  166.   tb = XTOOLBAR_BUTTON (button);
  167.   old_flag = tb->down;
  168.  
  169.   /* If the button is ignored, don't do anything. */
  170.   if (!tb->enabled)
  171.     return Qnil;
  172.  
  173.   /* If flag is nil, unset the down flag, otherwise set it to true.
  174.      This also triggers an immediate redraw of the button if the flag
  175.      does change. */
  176.  
  177.   if (NILP (flag))
  178.     tb->down = 0;
  179.   else
  180.     tb->down = 1;
  181.  
  182.   if (tb->down != old_flag)
  183.     {
  184.       struct frame *f = XFRAME (tb->frame);
  185.       struct device *d;
  186.  
  187.       if (DEVICEP (f->device))
  188.     {
  189.       d = XDEVICE (f->device);
  190.  
  191.       if (DEVICE_LIVE_P (XDEVICE (f->device)))
  192.         {
  193.           tb->dirty = 1;
  194.           MAYBE_DEVMETH (d, output_toolbar_button, (f, button));
  195.         }
  196.     }
  197.     }
  198.  
  199.   return Qnil;
  200. }    
  201.  
  202.  
  203. static Lisp_Object
  204. toolbar_from_toolbar_position (Lisp_Object position)
  205. {
  206.   if (EQ (position, Qtop))
  207.     return Vtop_toolbar;
  208.   else if (EQ (position, Qbottom))
  209.     return Vbottom_toolbar;
  210.   else if (EQ (position, Qleft))
  211.     return Vleft_toolbar;
  212.   else if (EQ (position, Qright))
  213.     return Vright_toolbar;
  214.   signal_simple_error ("Invalid toolbar position", position);
  215.   return Qnil; /* not reached */
  216. }
  217.  
  218. DEFUN ("set-default-toolbar-position", Fset_default_toolbar_position,
  219.        Sset_default_toolbar_position, 1, 1, 0,
  220.   "Set the position that the `default-toolbar' will be displayed at.\n\
  221. Valid positions are 'top, 'bottom, 'left and 'right.\n\
  222. See `default-toolbar-position'.")
  223.      (position)
  224.      Lisp_Object position;
  225. {
  226.   Lisp_Object current_inheriting =
  227.     toolbar_from_toolbar_position (Vdefault_toolbar_position);
  228.   Lisp_Object new_inheriting =
  229.     toolbar_from_toolbar_position (position);
  230.   if (!EQ (current_inheriting, new_inheriting))
  231.     {
  232.       /* The following calls will automatically cause the dirty
  233.      flags to be set */
  234.       set_specifier_fallback (current_inheriting, Qnil);
  235.       set_specifier_fallback (new_inheriting, Vdefault_toolbar);
  236.       Vdefault_toolbar_position = position;
  237.     }
  238.  
  239.   return position;
  240. }
  241.  
  242. DEFUN ("default-toolbar-position", Fdefault_toolbar_position,
  243.        Sdefault_toolbar_position, 0, 0, 0,
  244.   "Return the position that the `default-toolbar' will be displayed at.\n\
  245. The `default-toolbar' will only be displayed here if the corresponding\n\
  246. position-specific toolbar specifier does not provide a value.")
  247.     ()
  248. {
  249.   return Vdefault_toolbar_position;
  250. }
  251.  
  252.  
  253. static Lisp_Object
  254. update_toolbar_button (struct frame *f, struct toolbar_button *tb,
  255.                Lisp_Object desc, int pushright)
  256. {
  257.   Lisp_Object *elt, glyphs, retval, buffer;
  258.   struct gcpro gcpro1, gcpro2;
  259.  
  260.   elt = vector_data (XVECTOR (desc));
  261.   buffer = XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer;
  262.  
  263.   if (!tb)
  264.     {
  265.       tb = alloc_lcrecord (sizeof (struct toolbar_button),
  266.                lrecord_toolbar_button);
  267.       tb->next = Qnil;
  268.       XSETFRAME (tb->frame, f);
  269.       tb->up_glyph = Qnil;
  270.       tb->down_glyph = Qnil;
  271.       tb->disabled_glyph = Qnil;
  272.       tb->cap_up_glyph = Qnil;
  273.       tb->cap_down_glyph = Qnil;
  274.       tb->cap_disabled_glyph = Qnil;
  275.       tb->callback = Qnil;
  276.       tb->enabled_p = Qnil;
  277.       tb->help_string = Qnil;
  278.  
  279.       tb->enabled = 0;
  280.       tb->down = 0;
  281.       tb->pushright = pushright;
  282.       tb->blank = 0;
  283.       tb->x = tb->y = tb->width = tb->height = -1;
  284.       tb->dirty = 1;
  285.     }
  286.   XSETTOOLBAR_BUTTON (retval, tb);
  287.  
  288.   /* Let's make sure nothing gets mucked up by the potential call to
  289.      eval farther down. */
  290.   GCPRO2 (retval, desc);
  291.  
  292.   glyphs = (CONSP (elt[0]) ? elt[0] : symbol_value_in_buffer (elt[0], buffer));
  293.  
  294.   /* If this is true we have a blank, otherwise it is an actual
  295.      button. */
  296.   if (KEYWORDP (glyphs))
  297.     {
  298.       int pos;
  299.       int style_seen = 0;
  300.       int size_seen = 0;
  301.  
  302.       if (!tb->blank)
  303.     {
  304.       tb->blank = 1;
  305.       tb->dirty = 1;
  306.     }
  307.  
  308.       for (pos = 0; pos < vector_length (XVECTOR (desc)); pos += 2)
  309.     {
  310.       Lisp_Object key = elt[pos];
  311.       Lisp_Object val = elt[pos + 1];
  312.  
  313.       if (EQ (key, Q_style))
  314.         {
  315.           style_seen = 1;
  316.  
  317.           if (EQ (val, Q2D) || EQ (val, Q2d))
  318.         {
  319.           if (!EQ (Qnil, tb->up_glyph) || !EQ (Qt, tb->disabled_glyph))
  320.             {
  321.               tb->up_glyph = Qnil;
  322.               tb->disabled_glyph = Qt;
  323.               tb->dirty = 1;
  324.             }
  325.         }
  326.           else if (EQ (val, Q3D) || (EQ (val, Q3d)))
  327.         {
  328.           if (!EQ (Qt, tb->up_glyph) || !EQ (Qnil, tb->disabled_glyph))
  329.             {
  330.               tb->up_glyph = Qt;
  331.               tb->disabled_glyph = Qnil;
  332.               tb->dirty = 1;
  333.             }
  334.         }
  335.         }
  336.       else if (EQ (key, Q_size))
  337.         {
  338.           size_seen = 1;
  339.  
  340.           if (!EQ (val, tb->down_glyph))
  341.         {
  342.           tb->down_glyph = val;
  343.           tb->dirty = 1;
  344.         }
  345.         }
  346.     }
  347.  
  348.       if (!style_seen)
  349.     {
  350.       /* The default style is 3D. */
  351.       if (!EQ (Qt, tb->up_glyph) || !EQ (Qnil, tb->disabled_glyph))
  352.         {
  353.           tb->up_glyph = Qt;
  354.           tb->disabled_glyph = Qnil;
  355.           tb->dirty = 1;
  356.         }
  357.     }
  358.  
  359.       if (!size_seen)
  360.     {
  361.       /* The default width is set to nil.  The device specific
  362.              code will fill it in at its discretion. */
  363.       if (!NILP (tb->down_glyph))
  364.         {
  365.           tb->down_glyph = Qnil;
  366.           tb->dirty = 1;
  367.         }
  368.     }
  369.  
  370.       /* The rest of these fields are not used by blanks.  We make
  371.          sure they are nulled out in case this button object formerly
  372.          represented a real button. */
  373.       if (!NILP (tb->callback)
  374.       || !NILP (tb->enabled_p)
  375.       || !NILP (tb->help_string))
  376.     {
  377.       tb->cap_up_glyph = Qnil;
  378.       tb->cap_down_glyph = Qnil;
  379.       tb->cap_disabled_glyph = Qnil;
  380.       tb->callback = Qnil;
  381.       tb->enabled_p = Qnil;
  382.       tb->help_string = Qnil;
  383.       tb->dirty = 1;
  384.     }
  385.     }
  386.   else
  387.     {
  388.       if (tb->blank)
  389.     {
  390.       tb->blank = 0;
  391.       tb->dirty = 1;
  392.     }
  393.  
  394.       /* We know that we at least have an up_glyph. */
  395.       if (!EQ (XCAR (glyphs), tb->up_glyph))
  396.     {
  397.       tb->up_glyph = XCAR (glyphs);
  398.       tb->dirty = 1;
  399.     }
  400.       glyphs = XCDR (glyphs);
  401.  
  402.       /* We might have a down_glyph. */
  403.       if (!NILP (glyphs))
  404.     {
  405.       if (!EQ (XCAR (glyphs), tb->down_glyph))
  406.         {
  407.           tb->down_glyph = XCAR (glyphs);
  408.           tb->dirty = 1;
  409.         }
  410.       glyphs = XCDR (glyphs);
  411.     }
  412.       else
  413.     tb->down_glyph = Qnil;
  414.  
  415.       /* We might have a disabled_glyph. */
  416.       if (!NILP (glyphs))
  417.     {
  418.       if (!EQ (XCAR (glyphs), tb->disabled_glyph))
  419.         {
  420.           tb->disabled_glyph = XCAR (glyphs);
  421.           tb->dirty = 1;
  422.         }
  423.       glyphs = XCDR (glyphs);
  424.     }
  425.       else
  426.     tb->disabled_glyph = Qnil;
  427.  
  428.       /* We might have a cap_up_glyph. */
  429.       if (!NILP (glyphs))
  430.     {
  431.       if (!EQ (XCAR (glyphs), tb->cap_up_glyph))
  432.         {
  433.           tb->cap_up_glyph = XCAR (glyphs);
  434.           tb->dirty = 1;
  435.         }
  436.       glyphs = XCDR (glyphs);
  437.     }
  438.       else
  439.     tb->cap_up_glyph = Qnil;
  440.  
  441.       /* We might have a cap_down_glyph. */
  442.       if (!NILP (glyphs))
  443.     {
  444.       if (!EQ (XCAR (glyphs), tb->cap_down_glyph))
  445.         {
  446.           tb->cap_down_glyph = XCAR (glyphs);
  447.           tb->dirty = 1;
  448.         }
  449.       glyphs = XCDR (glyphs);
  450.     }
  451.       else
  452.     tb->cap_down_glyph = Qnil;
  453.  
  454.       /* We might have a cap_disabled_glyph. */
  455.       if (!NILP (glyphs))
  456.     {
  457.       if (!EQ (XCAR (glyphs), tb->cap_disabled_glyph))
  458.         {
  459.           tb->cap_disabled_glyph = XCAR (glyphs);
  460.           tb->dirty = 1;
  461.         }
  462.     }
  463.       else
  464.     tb->cap_disabled_glyph = Qnil;
  465.  
  466.       /* Update the callback. */
  467.       if (!EQ (tb->callback, elt[1]))
  468.     {
  469.       tb->callback = elt[1];
  470.       /* This does not have an impact on the display properties of the
  471.          button so we do not mark it as dirty if it has changed. */
  472.     }
  473.  
  474.       /* Update the enabled field. */
  475.       if (!EQ (tb->enabled_p, elt[2]))
  476.     {
  477.       tb->enabled_p = elt[2];
  478.       tb->dirty = 1;
  479.     }
  480.  
  481.       /* We always do the following because if the enabled status is
  482.      determined by a function its decision may change without us being
  483.      able to detect it. */
  484.       {
  485.     int old_enabled = tb->enabled;
  486.  
  487.     if (NILP (tb->enabled_p))
  488.       tb->enabled = 0;
  489.     else if (EQ (tb->enabled_p, Qt))
  490.       tb->enabled = 1;
  491.     else
  492.       {
  493.         if (NILP (tb->enabled_p) || EQ (tb->enabled_p, Qt))
  494.           /* short-circuit the common case for speed */
  495.           tb->enabled = !NILP (tb->enabled_p);
  496.         else
  497.           {
  498.         Lisp_Object result =
  499.           eval_in_buffer_trapping_errors
  500.             ("Error in toolbar enabled-p form",
  501.              XBUFFER
  502.              (WINDOW_BUFFER
  503.               (XWINDOW (FRAME_SELECTED_WINDOW (f)))),
  504.              tb->enabled_p);
  505.         if (UNBOUNDP (result))
  506.           /* #### if there was an error in the enabled-p
  507.              form, should we pretend like it's enabled
  508.              or disabled? */
  509.           tb->enabled = 0;
  510.         else
  511.           tb->enabled = !NILP (result);
  512.           }
  513.       }
  514.  
  515.     if (old_enabled != tb->enabled)
  516.       tb->dirty = 1;
  517.       }
  518.  
  519.       /* Update the help echo string. */
  520.       if (!EQ (tb->help_string, elt[3]))
  521.     {
  522.       tb->help_string = elt[3];
  523.       /* This does not have an impact on the display properties of the
  524.          button so we do not mark it as dirty if it has changed. */
  525.     }
  526.     }
  527.  
  528.   /* If this flag changes, the position is changing for sure unless
  529.      some very unlikely geometry occurs. */
  530.   if (tb->pushright != pushright)
  531.     {
  532.       tb->pushright = pushright;
  533.       tb->dirty = 1;
  534.     }
  535.  
  536.   /* The position and size fields are only manipulated in the
  537.      device-dependent code. */
  538.   UNGCPRO;
  539.   return retval;
  540. }
  541.  
  542. static Lisp_Object
  543. compute_frame_toolbar_buttons (struct frame *f, enum toolbar_pos pos,
  544.                    Lisp_Object toolbar)
  545. {
  546.   Lisp_Object buttons, prev_button, first_button;
  547.   Lisp_Object orig_toolbar = toolbar;
  548.   int pushright_seen = 0;
  549.   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
  550.  
  551.   first_button = FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons;
  552.   buttons = prev_button = first_button;
  553.  
  554.   /* Yes, we're being paranoid. */
  555.   GCPRO5 (toolbar, buttons, prev_button, first_button, orig_toolbar);
  556.  
  557.   if (NILP (toolbar))
  558.     {
  559.       /* The output mechanisms will take care of clearing the former
  560.          toolbar. */
  561.       UNGCPRO;
  562.       return Qnil;
  563.     }
  564.  
  565.   if (!CONSP (toolbar))
  566.     {
  567.       UNGCPRO;
  568.       signal_simple_error ("toolbar description must be a list", toolbar);
  569.     }
  570.  
  571.   /* First synchronize any existing buttons. */
  572.   while (!NILP (toolbar) && !NILP (buttons))
  573.     {
  574.       struct toolbar_button *tb;
  575.  
  576.       if (NILP (XCAR (toolbar)))
  577.     {
  578.       if (pushright_seen)
  579.         {
  580.           UNGCPRO;
  581.           signal_simple_error
  582.         ("more than one partition (nil) in toolbar description",
  583.          orig_toolbar);
  584.         }
  585.       else
  586.         pushright_seen = 1;
  587.     }
  588.       else
  589.     {
  590.       tb = XTOOLBAR_BUTTON (buttons);
  591.       update_toolbar_button (f, tb, XCAR (toolbar), pushright_seen);
  592.       prev_button = buttons;
  593.       buttons = tb->next;
  594.     }
  595.  
  596.       toolbar = XCDR (toolbar);
  597.     }
  598.  
  599.   /* If we hit the end of the toolbar, then clean up any excess
  600.      buttons and return. */
  601.   if (NILP (toolbar))
  602.     {
  603.       if (!NILP (buttons))
  604.     {
  605.       /* If this is the case the the only thing we saw was a
  606.              pushright marker. */
  607.       if (EQ (buttons, first_button))
  608.         {
  609.           UNGCPRO;
  610.           return Qnil;
  611.         }
  612.       else
  613.         XTOOLBAR_BUTTON (prev_button)->next = Qnil;
  614.     }
  615.       UNGCPRO;
  616.       return first_button;
  617.     }
  618.  
  619.   /* At this point there are more buttons on the toolbar than we
  620.      actually have in existence. */
  621.   while (!NILP (toolbar))
  622.     {
  623.       Lisp_Object new_button;
  624.  
  625.       if (NILP (XCAR (toolbar)))
  626.     {
  627.       if (pushright_seen)
  628.         {
  629.           UNGCPRO;
  630.           signal_simple_error
  631.         ("more than one partition (nil) in toolbar description",
  632.          orig_toolbar);
  633.         }
  634.       else
  635.         pushright_seen = 1;
  636.     }
  637.       else
  638.     {
  639.       new_button = update_toolbar_button (f, NULL, XCAR (toolbar),
  640.                           pushright_seen);
  641.  
  642.       if (NILP (first_button))
  643.         {
  644.           first_button = prev_button = new_button;
  645.         }
  646.       else
  647.         {
  648.           XTOOLBAR_BUTTON (prev_button)->next = new_button;
  649.           prev_button = new_button;
  650.         }
  651.     }
  652.  
  653.       toolbar = XCDR (toolbar);
  654.     }
  655.  
  656.   UNGCPRO;
  657.   return first_button;
  658. }
  659.  
  660. static int
  661. set_frame_toolbar (struct frame *f, enum toolbar_pos pos, int first_time_p)
  662. {
  663.   Lisp_Object toolbar, buttons;
  664.   Lisp_Object buffer = XWINDOW (f->selected_window)->buffer;
  665.   int size = 0;
  666.  
  667.   switch (pos)
  668.     {
  669.     case TOP_TOOLBAR:
  670.       toolbar = Fspecifier_instance (Vtop_toolbar,
  671.                      f->selected_window, Qnil, Qnil);
  672.       break;
  673.     case BOTTOM_TOOLBAR:
  674.       toolbar = Fspecifier_instance (Vbottom_toolbar,
  675.                      f->selected_window, Qnil, Qnil);
  676.       break;
  677.     case LEFT_TOOLBAR:
  678.       toolbar = Fspecifier_instance (Vleft_toolbar,
  679.                      f->selected_window, Qnil, Qnil);
  680.       break;
  681.     case RIGHT_TOOLBAR:
  682.       toolbar = Fspecifier_instance (Vright_toolbar,
  683.                      f->selected_window, Qnil, Qnil);
  684.       break;
  685.     default:
  686.       abort ();
  687.     }
  688.   size = XINT (f->toolbar_size[pos]);
  689.  
  690.   if (NILP (f->toolbar_data[pos]))
  691.     {
  692.       struct toolbar_data *td = alloc_lcrecord (sizeof (struct toolbar_data),
  693.                         lrecord_toolbar_data);
  694.  
  695.       td->last_toolbar_buffer = Qnil;
  696.       td->toolbar_buttons = Qnil;
  697.       XSETTOOLBAR_DATA (f->toolbar_data[pos], td);
  698.     }
  699.  
  700.   if (size)
  701.     buttons = compute_frame_toolbar_buttons (f, pos, toolbar);
  702.   else
  703.     buttons = Qnil;
  704.  
  705.   FRAME_TOOLBAR_DATA (f, pos)->last_toolbar_buffer = buffer;
  706.   FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons = buttons;
  707.  
  708.   return (size && !NILP (toolbar));
  709. }
  710.  
  711. #define COMPUTE_TOOLBAR_DATA(position)                    \
  712.   do                                    \
  713.     {                                    \
  714.       toolbar_changed =                            \
  715.     (f->toolbar_changed                        \
  716.      || NILP (f->toolbar_data[position])                \
  717.      || (!EQ (FRAME_TOOLBAR_DATA (f, position)->last_toolbar_buffer, \
  718.           XWINDOW (f->selected_window)->buffer)));        \
  719.                                     \
  720.       toolbar_was_visible =                        \
  721.          (!NILP (f->toolbar_data[position])                \
  722.           && !NILP (FRAME_TOOLBAR_DATA (f, position)->toolbar_buttons));\
  723.       toolbar_will_be_visible = toolbar_was_visible;            \
  724.                                     \
  725.       if (toolbar_changed)                        \
  726.     toolbar_will_be_visible =                    \
  727.            set_frame_toolbar (f, position, first_time_p);        \
  728.                                     \
  729.       toolbar_visibility_changed =                    \
  730.     (toolbar_was_visible != toolbar_will_be_visible);        \
  731.                                     \
  732.       if (toolbar_visibility_changed)                    \
  733.         frame_changed_size = 1;                        \
  734.     } while (0)
  735.  
  736. static void
  737. compute_frame_toolbars_data (struct frame *f, int first_time_p)
  738. {
  739.   int toolbar_changed;
  740.   int toolbar_was_visible, toolbar_will_be_visible;
  741.   int toolbar_visibility_changed;
  742.   int frame_changed_size = 0;
  743.  
  744.   COMPUTE_TOOLBAR_DATA (TOP_TOOLBAR);
  745.   COMPUTE_TOOLBAR_DATA (BOTTOM_TOOLBAR);
  746.   COMPUTE_TOOLBAR_DATA (LEFT_TOOLBAR);
  747.   COMPUTE_TOOLBAR_DATA (RIGHT_TOOLBAR);
  748.  
  749.   /* The frame itself doesn't actually change size, but the usable
  750.      text area does.  All we have to do is call change_frame_size with
  751.      the current height and width parameters and it will readjust for
  752.      all changes in the toolbars. */
  753.   if (frame_changed_size && !first_time_p)
  754.     change_frame_size (f, FRAME_HEIGHT (f), FRAME_WIDTH (f), 0, 0);
  755. }
  756. #undef COMPUTE_TOOLBAR_DATA
  757.  
  758. void
  759. update_frame_toolbars (struct frame *f)
  760. {
  761.   struct device *d = XDEVICE (f->device);
  762.   Lisp_Object buffer = XWINDOW (f->selected_window)->buffer;
  763.  
  764.   /* If the buffer of the selected window is not equal to the
  765.      last_toolbar_buffer value for any of the toolbars, then the
  766.      toolbars need to be recomputed. */
  767.   if ((HAS_DEVMETH_P (d, output_frame_toolbars))
  768.       && (f->toolbar_changed
  769.       || !EQ (FRAME_TOOLBAR_BUFFER (f, TOP_TOOLBAR), buffer)
  770.       || !EQ (FRAME_TOOLBAR_BUFFER (f, BOTTOM_TOOLBAR), buffer)
  771.       || !EQ (FRAME_TOOLBAR_BUFFER (f, LEFT_TOOLBAR), buffer)
  772.       || !EQ (FRAME_TOOLBAR_BUFFER (f, RIGHT_TOOLBAR), buffer)))
  773.     {
  774.       /* The minibuffer isn't allowed to alter the toolbar.  We still
  775.          output any existing toolbar information to ensure that it
  776.          gets redrawn properly. */
  777.       if (!MINI_WINDOW_P (XWINDOW (f->selected_window)))
  778.     compute_frame_toolbars_data (f, 0);
  779.  
  780.       DEVMETH (d, output_frame_toolbars, (f));
  781.     }
  782.  
  783.   f->toolbar_changed = 0;
  784. }
  785.  
  786. void
  787. init_frame_toolbars (struct frame *f)
  788. {
  789.   struct device *d = XDEVICE (f->device);
  790.  
  791.   /* If there isn't any output routine, then this device type doesn't
  792.      support toolbars. */
  793.   if (HAS_DEVMETH_P (d, output_frame_toolbars))
  794.     {
  795.       Lisp_Object frame = Qnil;
  796.  
  797.       compute_frame_toolbars_data (f, 1);
  798.       XSETFRAME (frame, f);
  799.       call_critical_lisp_code (XDEVICE (FRAME_DEVICE (f)),
  800.                    Qinit_toolbar_from_resources,
  801.                    frame);
  802.       MAYBE_DEVMETH (d, initialize_frame_toolbars, (f));
  803.     }
  804. }
  805.  
  806. void
  807. init_device_toolbars (struct device *d)
  808. {
  809.   Lisp_Object device = Qnil;
  810.  
  811.   XSETDEVICE (device, d);
  812.   if (HAS_DEVMETH_P (d, output_frame_toolbars))
  813.     call_critical_lisp_code (d,
  814.                  Qinit_toolbar_from_resources,
  815.                  device);
  816. }
  817.  
  818. void
  819. init_global_toolbars (struct device *d)
  820. {
  821.   if (HAS_DEVMETH_P (d, output_frame_toolbars))
  822.     call_critical_lisp_code (d,
  823.                  Qinit_toolbar_from_resources,
  824.                  Qglobal);
  825. }
  826.  
  827. void
  828. free_frame_toolbars (struct frame *f)
  829. {
  830.   struct device *d = XDEVICE (f->device);
  831.  
  832.   /* If we had directly allocated any memory for the toolbars instead
  833.      of using all Lisp_Objects this is where we would now free it. */
  834.  
  835.   MAYBE_DEVMETH (d, free_frame_toolbars, (f));
  836. }
  837.  
  838. void
  839. get_toolbar_coords (struct frame *f, enum toolbar_pos pos, int *x, int *y,
  840.             int *width, int *height, int *vert, int for_layout)
  841. {
  842.   int visible_top_toolbar_height, visible_bottom_toolbar_height;
  843.   int adjust = (for_layout ? 1 : 0);
  844.  
  845.   /* The top and bottom toolbars take precedence over the left and
  846.      right. */
  847.   visible_top_toolbar_height = (FRAME_TOP_TOOLBAR_VISIBLE (f)
  848.                 ? FRAME_TOP_TOOLBAR_HEIGHT (f)
  849.                 : 0);
  850.   visible_bottom_toolbar_height = (FRAME_BOTTOM_TOOLBAR_VISIBLE (f)
  851.                 ? FRAME_BOTTOM_TOOLBAR_HEIGHT (f)
  852.                 : 0);
  853.  
  854.   /* We adjust the width and height by one to give us a narrow border
  855.      at the ouside edges.  However, when we are simply determining
  856.      toolbar location we don't want to do that. */
  857.  
  858.   switch (pos)
  859.     {
  860.     case TOP_TOOLBAR:
  861.       *x = 1;
  862.       *y = 0;    /* #### should be 1 if no menubar */
  863.       *width = FRAME_PIXWIDTH (f) - 2;
  864.       *height = FRAME_TOP_TOOLBAR_HEIGHT (f) - adjust;
  865.       *vert = 0;
  866.       break;
  867.     case BOTTOM_TOOLBAR:
  868.       *x = 1;
  869.       *y = FRAME_PIXHEIGHT (f) - FRAME_BOTTOM_TOOLBAR_HEIGHT (f);
  870.       *width = FRAME_PIXWIDTH (f) - 2;
  871.       *height = FRAME_BOTTOM_TOOLBAR_HEIGHT (f) - adjust;
  872.       *vert = 0;
  873.       break;
  874.     case LEFT_TOOLBAR:
  875.       *x = 1;
  876.       *y = visible_top_toolbar_height;
  877.       *width = FRAME_LEFT_TOOLBAR_WIDTH (f) - adjust;
  878.       *height = (FRAME_PIXHEIGHT (f) - visible_top_toolbar_height -
  879.          visible_bottom_toolbar_height - 1);
  880.       *vert = 1;
  881.       break;
  882.     case RIGHT_TOOLBAR:
  883.       *x = FRAME_PIXWIDTH (f) - FRAME_RIGHT_TOOLBAR_WIDTH (f);
  884.       *y = visible_top_toolbar_height;
  885.       *width = FRAME_RIGHT_TOOLBAR_WIDTH (f) - adjust;
  886.       *height = (FRAME_PIXHEIGHT (f) - visible_top_toolbar_height -
  887.          visible_bottom_toolbar_height);
  888.       *vert = 1;
  889.       break;
  890.     default:
  891.       abort ();
  892.     }
  893. }
  894.  
  895. #define CHECK_TOOLBAR(pos)                        \
  896.   do                                    \
  897.     {                                    \
  898.       get_toolbar_coords (f, pos, &x, &y, &width, &height, &vert, 0);    \
  899.       if ((x_coord >= x) && (x_coord < (x + width)))            \
  900.     {                                \
  901.       if ((y_coord >= y) && (y_coord < (y + height)))        \
  902.         {                                \
  903.           return (FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons);    \
  904.         }                                \
  905.     }                                \
  906.     } while (0)
  907.  
  908. static Lisp_Object
  909. toolbar_buttons_at_pixpos (struct frame *f, int x_coord, int y_coord)
  910. {
  911.   int x, y, width, height, vert;
  912.  
  913.   if (FRAME_TOP_TOOLBAR_VISIBLE (f))
  914.     CHECK_TOOLBAR (TOP_TOOLBAR);
  915.   if (FRAME_BOTTOM_TOOLBAR_VISIBLE (f))
  916.     CHECK_TOOLBAR (BOTTOM_TOOLBAR);
  917.   if (FRAME_LEFT_TOOLBAR_VISIBLE (f))
  918.     CHECK_TOOLBAR (LEFT_TOOLBAR);
  919.   if (FRAME_RIGHT_TOOLBAR_VISIBLE (f))
  920.     CHECK_TOOLBAR (RIGHT_TOOLBAR);
  921.  
  922.   return Qnil;
  923. }
  924. #undef CHECK_TOOLBAR
  925.  
  926. /* The device dependent code actually does the work of positioning the
  927.    buttons, but we are free to access that information at this
  928.    level. */
  929. Lisp_Object
  930. toolbar_button_at_pixpos (struct frame *f, int x_coord, int y_coord)
  931. {
  932.   Lisp_Object buttons = toolbar_buttons_at_pixpos (f, x_coord, y_coord);
  933.  
  934.   if (NILP (buttons))
  935.     return Qnil;
  936.  
  937.   while (!NILP (buttons))
  938.     {
  939.       struct toolbar_button *tb = XTOOLBAR_BUTTON (buttons);
  940.  
  941.       if ((x_coord >= tb->x) && (x_coord < (tb->x + tb->width)))
  942.     {
  943.       if ((y_coord >= tb->y) && (y_coord < (tb->y + tb->height)))
  944.         {
  945.           /* If we are over a blank, return nil. */
  946.           if (tb->blank)
  947.         return Qnil;
  948.           else
  949.         return buttons;
  950.         }
  951.     }
  952.  
  953.       buttons = tb->next;
  954.     }
  955.  
  956.   /* We must be over a blank in the toolbar. */
  957.   return Qnil;
  958. }
  959.  
  960.  
  961. /************************************************************************/
  962. /*                        Toolbar specifier type                        */
  963. /************************************************************************/
  964.  
  965. DEFINE_SPECIFIER_TYPE (toolbar);
  966.  
  967. #define CTB_ERROR(msg)                \
  968.   do {                        \
  969.     if (!NILP (no_error))            \
  970.       return Qnil;                \
  971.     else                    \
  972.       signal_simple_error (msg, button);    \
  973.   } while (0)
  974.  
  975. /* Returns Q_style if key was :style, Qt if ok otherwise, Qnil if error. */
  976. static Lisp_Object
  977. check_toolbar_button_keywords (Lisp_Object button, Lisp_Object key,
  978.                    Lisp_Object val, Lisp_Object no_error)
  979. {
  980.   if (!KEYWORDP (key))
  981.     {
  982.       if (!NILP (no_error))
  983.     return Qnil;
  984.       else
  985.     signal_simple_error_2 ("not a keyword", key, button);
  986.     }
  987.  
  988.   if (EQ (key, Q_style))
  989.     {
  990.       if (!EQ (val, Q2D)
  991.       && !EQ (val, Q3D)
  992.       && !EQ (val, Q2d)
  993.       && !EQ (val, Q3d))
  994.     CTB_ERROR ("unrecognized toolbar blank style");
  995.  
  996.       return Q_style;
  997.     }
  998.   else if (EQ (key, Q_size))
  999.     {
  1000.       if (!NATNUMP (val))
  1001.     CTB_ERROR ("invalid toolbar blank size");
  1002.     }
  1003.   else
  1004.     {
  1005.       CTB_ERROR ("invalid toolbar blank keyword");
  1006.     }
  1007.  
  1008.   return Qt;
  1009. }
  1010.  
  1011. /* toolbar button spec is [pixmap-pair function enabled-p help]
  1012.                    or [:style 2d-or-3d :size width-or-height] */
  1013.  
  1014. DEFUN ("check-toolbar-button-syntax", Fcheck_toolbar_button_syntax,
  1015.        Scheck_toolbar_button_syntax, 1, 2, 0,
  1016.        "Verify the syntax of entry BUTTON in a toolbar description list.\n\
  1017. If you want to verify the syntax of a toolbar description list as a\n\
  1018. whole, use `check-valid-instantiator' with a specifier type of 'toolbar.")
  1019.   (button, no_error)
  1020.   Lisp_Object button, no_error;
  1021. {
  1022.   Lisp_Object *elt, glyphs, value;
  1023.   int len;
  1024.  
  1025.   if (!VECTORP (button))
  1026.     CTB_ERROR ("toolbar button descriptors must be vectors");
  1027.   elt = vector_data (XVECTOR (button));
  1028.  
  1029.   if (vector_length (XVECTOR (button)) == 2)
  1030.     {
  1031.       if (!EQ (Q_style, check_toolbar_button_keywords (button, elt[0],
  1032.                                elt[1], no_error)))
  1033.     CTB_ERROR ("must specify toolbar blank style");
  1034.  
  1035.       return Qt;
  1036.     }
  1037.  
  1038.   if (vector_length (XVECTOR (button)) != 4)
  1039.     CTB_ERROR ("toolbar button descriptors must be 2 or 4 long");
  1040.  
  1041.   /* The first element must be a list of glyphs of length 1-6.  The
  1042.      first entry is the pixmap for the up state, the second for the
  1043.      down state, the third for the disabled state, the fourth for the
  1044.      captioned up state, the fifth for the captioned down state and
  1045.      the sixth for the captioned disabled state.  Only the up state is
  1046.      mandatory. */
  1047.   if (!CONSP (elt[0]))
  1048.     {
  1049.       /* We can't check the buffer-local here because we don't know
  1050.          which buffer to check in.  #### I think this is a bad thing.
  1051.          See if we can't get enough information to this function so
  1052.          that it can check. */
  1053.       value = Fsymbol_value (elt[0]);
  1054.  
  1055.       if (!CONSP (value))
  1056.     {
  1057.       if (KEYWORDP (elt[0]))
  1058.         {
  1059.           int fsty = 0;
  1060.  
  1061.           if (EQ (Q_style, check_toolbar_button_keywords (button, elt[0],
  1062.                                   elt[1],
  1063.                                   no_error)))
  1064.         fsty++;
  1065.  
  1066.           if (EQ (Q_style, check_toolbar_button_keywords (button, elt[2],
  1067.                                   elt[3],
  1068.                                   no_error)))
  1069.         fsty++;
  1070.  
  1071.           if (!fsty)
  1072.         CTB_ERROR ("must specify toolbar blank style");
  1073.           else if (EQ (elt[0], elt[2]))
  1074.         CTB_ERROR
  1075.           ("duplicate keywords in toolbar button blank description");
  1076.  
  1077.           return Qt;
  1078.         }
  1079.       else
  1080.         CTB_ERROR ("first element of button must be a list (of glyphs)");
  1081.     }
  1082.     }
  1083.   else
  1084.     value = elt[0];
  1085.  
  1086.   len = XINT (Flength (value));
  1087.   if (len < 1)
  1088.     CTB_ERROR ("toolbar button glyph list must have at least 1 entry");
  1089.   
  1090.   if (len > 6)
  1091.     CTB_ERROR ("toolbar button glyph list can have at most 6 entries");
  1092.  
  1093.   glyphs = value;
  1094.   while (!NILP (glyphs))
  1095.     {
  1096.       if (!GLYPHP (XCAR (glyphs)))
  1097.     {
  1098.       /* We allow nil for the down and disabled glyphs but not for
  1099.              the up glyph. */
  1100.       if (EQ (glyphs, value) || !NILP (XCAR (glyphs)))
  1101.         {
  1102.           CTB_ERROR
  1103.         ("all elements of toolbar button glyph list must be glyphs.");
  1104.         }
  1105.     }
  1106.       glyphs = XCDR (glyphs);
  1107.     }
  1108.  
  1109.   /* The second element is the function to run when the button is
  1110.      activated.  We do not do any checking on it because it is legal
  1111.      for the function to not be defined until after the toolbar is.
  1112.      It is the user's problem to get this right.
  1113.  
  1114.      The third element is either a boolean indicating the enabled
  1115.      status or a function used to determine it.  Again, it is the
  1116.      user's problem if this is wrong.
  1117.  
  1118.      The fourth element, if not nil, must be a string which will be
  1119.      displayed as the help echo. */
  1120.  
  1121.   /* #### This should be allowed to be a function returning a string
  1122.      as well as just a string. */
  1123.   if (!NILP (elt[3]) && !STRINGP (elt[3]))
  1124.     CTB_ERROR ("toolbar button help echo string must be a string");
  1125.  
  1126.   return Qt;
  1127. }
  1128. #undef CTB_ERROR
  1129.  
  1130. static int
  1131. toolbar_validate (Lisp_Object instantiator, int no_error)
  1132. {
  1133.   int pushright_seen = 0;
  1134.   Lisp_Object rest;
  1135.  
  1136.   if (NILP (instantiator))
  1137.     return 1;
  1138.  
  1139.   if (!CONSP (instantiator))
  1140.     {
  1141.       if (!no_error)
  1142.     signal_simple_error ("toolbar spec must be list or nil",
  1143.                  instantiator);
  1144.       else
  1145.     return 0;
  1146.     }
  1147.  
  1148.   for (rest = instantiator; !NILP (rest); rest = XCDR (rest))
  1149.     {
  1150.       if (!CONSP (rest))
  1151.     {
  1152.       if (!no_error)
  1153.         signal_simple_error ("bad list in toolbar spec",
  1154.                  instantiator);
  1155.       else
  1156.         return 0;
  1157.     }
  1158.       if (NILP (XCAR (rest)))
  1159.     {
  1160.       if (pushright_seen)
  1161.         {
  1162.           if (!no_error)
  1163.         error
  1164.           ("more than one partition (nil) in instantiator description");
  1165.           else
  1166.         return 0;
  1167.         }
  1168.       else
  1169.         pushright_seen = 1;
  1170.     }
  1171.       else
  1172.     {
  1173.       if (NILP (Fcheck_toolbar_button_syntax (XCAR (rest),
  1174.                           no_error ? Qt :
  1175.                           Qnil)))
  1176.         /* if there was an explanatory error, it already got
  1177.            signalled */
  1178.         return 0;
  1179.     }
  1180.     }
  1181.  
  1182.   return 1;
  1183. }
  1184.  
  1185. static void
  1186. toolbar_after_change (Lisp_Object specifier, Lisp_Object locale)
  1187. {
  1188.   /* #### This is overkill.  I really need to rethink the after-change
  1189.      functions to make them easier to use. */
  1190.   MARK_TOOLBAR_CHANGED;
  1191. }
  1192.  
  1193. DEFUN ("toolbar-specifier-p", Ftoolbar_specifier_p,
  1194.        Stoolbar_specifier_p, 1, 1, 0,
  1195.        "Return non-nil if OBJECT is an toolbar specifier.\n\
  1196. Toolbar specifiers are used to specify the format of a toolbar.\n\
  1197. The values of the variables `default-toolbar', `top-toolbar',\n\
  1198. `left-toolbar', `right-toolbar', and `bottom-toolbar' are always\n\
  1199. toolbar specifiers.  See `default-toolbar' for a description\n\
  1200. of a valid toolbar instantiator.")
  1201.      (object)
  1202.      Lisp_Object object;
  1203. {
  1204.   return (TOOLBAR_SPECIFIERP (object) ? Qt : Qnil);
  1205. }
  1206.  
  1207.  
  1208.  
  1209. static void
  1210. toolbar_size_changed_in_frame (Lisp_Object specifier, struct frame *f,
  1211.                    Lisp_Object oldval)
  1212. {
  1213.   MAYBE_FRAMEMETH (f, toolbar_size_changed_in_frame,
  1214.            (specifier, f, oldval));
  1215. }
  1216.  
  1217.  
  1218. void
  1219. syms_of_toolbar (void)
  1220. {
  1221.   defsymbol (&Qtoolbar, "toolbar");
  1222.  
  1223.   defsymbol (&Qtop, "top");
  1224.   defsymbol (&Qbottom, "bottom");
  1225.   defsymbol (&Qleft, "left");
  1226.   defsymbol (&Qright, "right");
  1227.  
  1228.   defsymbol (&Qtoolbar_buttonp, "toolbar-button-p");
  1229.   defsymbol (&Q2D, "2D");
  1230.   defsymbol (&Q3D, "3D");
  1231.   defsymbol (&Q2d, "2d");
  1232.   defsymbol (&Q3d, "3d");
  1233.   defsymbol (&Q_size, ":size");    Fset (Q_size, Q_size);
  1234.  
  1235.   defsymbol (&Qinit_toolbar_from_resources, "init-toolbar-from-resources");
  1236.   defsubr (&Stoolbar_button_p);
  1237.   defsubr (&Stoolbar_button_callback);
  1238.   defsubr (&Stoolbar_button_help_string);
  1239.   defsubr (&Stoolbar_button_enabled_p);
  1240.   defsubr (&Sset_toolbar_button_down_flag);
  1241.   defsubr (&Scheck_toolbar_button_syntax);
  1242.   defsubr (&Sset_default_toolbar_position);
  1243.   defsubr (&Sdefault_toolbar_position);
  1244.   defsubr (&Stoolbar_specifier_p);
  1245. }
  1246.  
  1247. void
  1248. vars_of_toolbar (void)
  1249. {
  1250.   staticpro (&Vdefault_toolbar_position);
  1251.   Vdefault_toolbar_position = Qtop;
  1252. }
  1253.  
  1254. void
  1255. specifier_type_create_toolbar (void)
  1256. {
  1257.   INITIALIZE_SPECIFIER_TYPE (toolbar, "toolbar", "toolbar-specifier-p");
  1258.  
  1259.   SPECIFIER_HAS_METHOD (toolbar, validate);
  1260.   SPECIFIER_HAS_METHOD (toolbar, after_change);
  1261. }
  1262.  
  1263. static void
  1264. toolbar_buttons_captioned_p_changed (Lisp_Object specifier, struct window *w,
  1265.                      Lisp_Object oldval)
  1266. {
  1267.   /* This could be smarter but I doubt that it would make any
  1268.      noticable difference given the infrequency with which this is
  1269.      probably going to be called. */
  1270.   MARK_TOOLBAR_CHANGED;
  1271. }
  1272.  
  1273. /* #### Do something about the unbelievable ugly contortions necessary
  1274.    to set the fallback values here. */
  1275.  
  1276. void
  1277. specifier_vars_of_toolbar (void)
  1278. {
  1279.   Lisp_Object elt;
  1280.       
  1281.   DEFVAR_SPECIFIER ("default-toolbar", &Vdefault_toolbar,
  1282.     "Specifier for a fallback toolbar.\n\
  1283. Use `set-specifier' to change this.\n\
  1284. \n\
  1285. The position of this toolbar is specified in the function\n\
  1286. `default-toolbar-position'.  If the corresponding position-\n\
  1287. specific toolbar (e.g. `top-toolbar' if `default-toolbar-position'\n\
  1288. is 'top) does not specify a toolbar in a particular domain,\n\
  1289. then the value of `default-toolbar' in that domain, if any,\n\
  1290. will be used instead.\n\
  1291. \n\
  1292. Note that the toolbar at any particular position will not be\n\
  1293. displayed unless its thickness (width or height, depending on\n\
  1294. orientation) is non-zero.  The thickness is controlled by the\n\
  1295. variables `top-toolbar-height', `bottom-toolbar-height',\n\
  1296. `left-toolbar-width', and `right-toolbar-width'.  By default,\n\
  1297. only `top-toolbar-height' has a non-zero value.\n\
  1298. \n\
  1299. The format of the instantiator for a toolbar is a list of\n\
  1300. toolbar-button-descriptors.  Each toolbar-button-descriptor\n\
  1301. is a vector in one of the following formats:\n\
  1302. \n\
  1303.   [GLYPH-LIST FUNCTION ENABLED-P HELP] or\n\
  1304.   [:style 2D-OR-3D] or\n\
  1305.   [:style 2D-OR-3D :size WIDTH-OR-HEIGHT] or\n\
  1306.   [:size WIDTH-OR-HEIGHT :style 2D-OR-3D]\n\
  1307. \n\
  1308. Optionally, one of the toolbar-button-descriptors may be nil\n\
  1309. instead of a vector; this signifies the division between\n\
  1310. the toolbar buttons that are to be displayed flush-left,\n\
  1311. and the buttons to be displayed flush-right.\n\
  1312. \n\
  1313. The first vector format above specifies a normal toolbar button;\n\
  1314. the others specify blank areas in the toolbar.\n\
  1315. \n\
  1316. For the first vector format:\n\
  1317. \n\
  1318. -- GLYPH-LIST should be a list of one to six glyphs (as created by\n\
  1319.    `make-glyph') or a symbol whose value is such a list.  The first\n\
  1320.    glyph, which must be provided, is the glyph used to display the\n\
  1321.    toolbar button when it is in the \"up\" (not pressed) state.  The\n\
  1322.    optional second glyph is for displaying the button when it is in\n\
  1323.    the \"down\" (pressed) state.  The optional third glyph is for when\n\
  1324.    the button is disabled.  The optional fourth, fifth and sixth glyphs\n\
  1325.    are used to specify captioned versions for the up, down and disabled\n\
  1326.    states respectively.  The function `toolbar-make-button-list' is\n\
  1327.    useful in creating these glyph lists.  The specifier variable\n\
  1328.    `toolbar-use-captions' controls whic glyphs are actually used.\n\
  1329. \n\
  1330.    Even if you do not provide separate down-state and disabled-state\n\
  1331.    glyphs, the user will still get visual feedback to indicate which\n\
  1332.    state the button is in.  Buttons in the up-state are displayed\n\
  1333.    with a shadowed border that gives a raised appearance to the\n\
  1334.    button.  Buttons in the down-state are displayed with shadows that\n\
  1335.    give a recessed appearance.  Buttons in the disabled state and\n\
  1336.    displayed with no shadows, giving a 2-d effect.\n\
  1337. \n\
  1338. -- The second element FUNCTION is a function to be called when the\n\
  1339.    toolbar button is activated (i.e. when the mouse is released over\n\
  1340.    the toolbar button, if the press occurred in the toolbar).  It\n\
  1341.    can be any form accepted by `call-interactively', since this is\n\
  1342.    how it is invoked.\n\
  1343. \n\
  1344. -- The third element ENABLED-P specifies whether the toolbar button\n\
  1345.    is enabled (disabled buttons do nothing when they are activated,\n\
  1346.    and are displayed differently; see above).  It should be either\n\
  1347.    a boolean or a form that evaluates to a boolean.\n\
  1348. \n\
  1349. -- The fourth element HELP, if non-nil, should be a string.  This\n\
  1350.    string is displayed in the echo area when the mouse passes over\n\
  1351.    the toolbar button.\n\
  1352. \n\
  1353. For the other vector formats (specifying blank areas of the toolbar):\n\
  1354. \n\
  1355. -- 2D-OR-3D should be one of the symbols '2d or '3d, indicating\n\
  1356.    whether the area is displayed with shadows (giving it a raised,\n\
  1357.    3-d appearance) or without shadows (giving it a flat appearance).\n\
  1358. \n\
  1359. -- WIDTH-OR-HEIGHT specifies the length, in pixels, of the blank\n\
  1360.    area.  If omitted, it defaults to a device-specific value\n\
  1361.    (8 pixels for X devices).");
  1362.  
  1363.   Vdefault_toolbar = Fmake_specifier (Qtoolbar);
  1364.  
  1365.   DEFVAR_SPECIFIER ("top-toolbar", &Vtop_toolbar,
  1366.     "Specifier for toolbar at the top of the frame.\n\
  1367. Use `set-specifier' to change this.\n\
  1368. See `default-toolbar' for a description of a valid toolbar instantiator.");
  1369.   Vtop_toolbar = Fmake_specifier (Qtoolbar);
  1370.   /* initially, top inherits from default; this can be
  1371.      changed with `set-default-toolbar-position'. */
  1372.   set_specifier_fallback (Vtop_toolbar, Vdefault_toolbar);
  1373.  
  1374.   DEFVAR_SPECIFIER ("bottom-toolbar", &Vbottom_toolbar,
  1375.     "Specifier for toolbar at the bottom of the frame.\n\
  1376. Use `set-specifier' to change this.\n\
  1377. See `default-toolbar' for a description of a valid toolbar instantiator.\n\
  1378. \n\
  1379. Note that by default the height of the bottom toolbar (controlled by\n\
  1380. `bottom-toolbar-height') is 0; thus, a bottom toolbar will not be\n\
  1381. displayed even if you provide a value for `bottom-toolbar'.");
  1382.   Vbottom_toolbar = Fmake_specifier (Qtoolbar);
  1383.  
  1384.   DEFVAR_SPECIFIER ("left-toolbar", &Vleft_toolbar,
  1385.     "Specifier for toolbar at the left edge of the frame.\n\
  1386. Use `set-specifier' to change this.\n\
  1387. See `default-toolbar' for a description of a valid toolbar instantiator.\n\
  1388. \n\
  1389. Note that by default the width of the left toolbar (controlled by\n\
  1390. `left-toolbar-width') is 0; thus, a left toolbar will not be\n\
  1391. displayed even if you provide a value for `left-toolbar'.");
  1392.   Vleft_toolbar = Fmake_specifier (Qtoolbar);
  1393.  
  1394.   DEFVAR_SPECIFIER ("right-toolbar", &Vright_toolbar,
  1395.     "Specifier for toolbar at the right edge of the frame.\n\
  1396. Use `set-specifier' to change this.\n\
  1397. See `default-toolbar' for a description of a valid toolbar instantiator.\n\
  1398. \n\
  1399. Note that by default the width of the right toolbar (controlled by\n\
  1400. `right-toolbar-width') is 0; thus, a right toolbar will not be\n\
  1401. displayed even if you provide a value for `right-toolbar'.");
  1402.   Vright_toolbar = Fmake_specifier (Qtoolbar);
  1403.  
  1404.   DEFVAR_SPECIFIER ("top-toolbar-height", &Vtop_toolbar_height,
  1405.     "*Height of top toolbar.\n\
  1406. This is a specifier; use `set-specifier' to change it.");
  1407.   Vtop_toolbar_height = Fmake_specifier (Qnatnum);
  1408.  
  1409.   elt = list1 (Fcons (list1 (Qtty), Qzero));
  1410. #ifdef HAVE_X_WINDOWS
  1411.   elt = Fcons (Fcons (list1 (Qx), make_number (DEFAULT_TOP_TOOLBAR_HEIGHT)), elt);
  1412. #endif
  1413. #ifdef HAVE_NEXTSTEP
  1414.   elt = Fcons (Fcons (list1 (Qns), make_number (DEFAULT_TOP_TOOLBAR_HEIGHT)), elt);
  1415. #endif
  1416.   set_specifier_fallback (Vtop_toolbar_height, elt);
  1417.   set_specifier_caching (Vtop_toolbar_height,
  1418.              slot_offset (struct window,
  1419.                       toolbar_size[TOP_TOOLBAR]),
  1420.              some_window_value_changed,
  1421.              slot_offset (struct frame,
  1422.                       toolbar_size[TOP_TOOLBAR]),
  1423.              toolbar_size_changed_in_frame);
  1424.  
  1425.   DEFVAR_SPECIFIER ("bottom-toolbar-height", &Vbottom_toolbar_height,
  1426.     "*Height of bottom toolbar.\n\
  1427. This is a specifier; use `set-specifier' to change it.");
  1428.   Vbottom_toolbar_height = Fmake_specifier (Qnatnum);
  1429.   elt = list1 (Fcons (list1 (Qtty), Qzero));
  1430. #ifdef HAVE_X_WINDOWS
  1431.   elt = Fcons (Fcons (list1 (Qx), make_number (DEFAULT_BOTTOM_TOOLBAR_HEIGHT)), elt);
  1432. #endif
  1433. #ifdef HAVE_NEXTSTEP
  1434.   elt = Fcons (Fcons (list1 (Qns), make_number (DEFAULT_BOTTOM_TOOLBAR_HEIGHT)), elt);
  1435. #endif
  1436.   set_specifier_fallback (Vbottom_toolbar_height, elt);
  1437.   set_specifier_caching (Vbottom_toolbar_height,
  1438.              slot_offset (struct window,
  1439.                       toolbar_size[BOTTOM_TOOLBAR]),
  1440.              some_window_value_changed,
  1441.              slot_offset (struct frame,
  1442.                       toolbar_size[BOTTOM_TOOLBAR]),
  1443.              toolbar_size_changed_in_frame);
  1444.  
  1445.   DEFVAR_SPECIFIER ("left-toolbar-width", &Vleft_toolbar_width,
  1446.     "*Width of left toolbar.\n\
  1447. This is a specifier; use `set-specifier' to change it.");
  1448.   Vleft_toolbar_width = Fmake_specifier (Qnatnum);
  1449.   elt = list1 (Fcons (list1 (Qtty), Qzero));
  1450. #ifdef HAVE_X_WINDOWS
  1451.   elt = Fcons (Fcons (list1 (Qx), make_number (DEFAULT_LEFT_TOOLBAR_WIDTH)), elt);
  1452. #endif
  1453. #ifdef HAVE_NEXTSTEP
  1454.   elt = Fcons (Fcons (list1 (Qns), make_number (DEFAULT_LEFT_TOOLBAR_WIDTH)), elt);
  1455. #endif
  1456.   set_specifier_fallback (Vleft_toolbar_width, elt);
  1457.   set_specifier_caching (Vleft_toolbar_width,
  1458.              slot_offset (struct window,
  1459.                       toolbar_size[LEFT_TOOLBAR]),
  1460.              some_window_value_changed,
  1461.              slot_offset (struct frame,
  1462.                       toolbar_size[LEFT_TOOLBAR]),
  1463.              toolbar_size_changed_in_frame);
  1464.  
  1465.   DEFVAR_SPECIFIER ("right-toolbar-width", &Vright_toolbar_width,
  1466.     "*Width of right toolbar.\n\
  1467. This is a specifier; use `set-specifier' to change it.");
  1468.   Vright_toolbar_width = Fmake_specifier (Qnatnum);
  1469.   elt = list1 (Fcons (list1 (Qtty), Qzero));
  1470. #ifdef HAVE_X_WINDOWS
  1471.   elt = Fcons (Fcons (list1 (Qx), make_number (DEFAULT_RIGHT_TOOLBAR_WIDTH)), elt);
  1472. #endif
  1473. #ifdef HAVE_NEXTSTEP
  1474.   elt = Fcons (Fcons (list1 (Qns), make_number (DEFAULT_RIGHT_TOOLBAR_WIDTH)), elt);
  1475. #endif
  1476.   set_specifier_fallback (Vright_toolbar_width, elt);
  1477.   set_specifier_caching (Vright_toolbar_width,
  1478.              slot_offset (struct window,
  1479.                       toolbar_size[RIGHT_TOOLBAR]),
  1480.              some_window_value_changed,
  1481.              slot_offset (struct frame,
  1482.                       toolbar_size[RIGHT_TOOLBAR]),
  1483.              toolbar_size_changed_in_frame);
  1484.  
  1485.   DEFVAR_SPECIFIER ("toolbar-buttons-captioned-p",
  1486.             &Vtoolbar_buttons_captioned_p,
  1487.     "*Whether the toolbar buttons are captioned.\n\
  1488. This will only have a visible effect for those toolbar buttons which had\n\
  1489. captioned versions specified.\n\
  1490. This is a specifier; use `set-specifier' to change it.");
  1491.   Vtoolbar_buttons_captioned_p = Fmake_specifier (Qboolean);
  1492.   set_specifier_fallback (Vtoolbar_buttons_captioned_p,
  1493.               list1 (Fcons (Qnil, Qt)));
  1494.   set_specifier_caching (Vtoolbar_buttons_captioned_p,
  1495.              slot_offset (struct window,
  1496.                       toolbar_buttons_captioned_p),
  1497.              toolbar_buttons_captioned_p_changed,
  1498.              0, 0);
  1499. }
  1500.